package game;

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.util.jar.Attributes.Name;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.UIManager;

import server.Server;

public class Game {
	
	private boolean host = false;
	
	JFrame frame = new JFrame("Start Game");
	
	public void run() {
		try {
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setLayout(new FlowLayout());
		frame.setResizable(false);
		
		JLabel l1 = new JLabel("Do you want to host or join a game?");
		frame.add(l1);
		
		JButton b1 = new JButton("Host");
		b1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				host = true;
				frame.dispose();
				start();
			}
		});
		frame.add(b1);
		
		JButton b2 = new JButton("Join");
		b2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				host = false;
				frame.dispose();
				start();
			}
		});
		frame.add(b2);
		
		frame.pack();
		frame.setLocationRelativeTo(null);
		frame.setVisible(true);
	}
	
	private void start() {
		if (host) {
			Server server = new Server();
			server.start(25565);
		} else {
			Network network = new Network("Test Guy", "localhost", 25565);
			network.connect();
		}
		
		//stop();
	}
	
	private void stop() {
		System.exit(0);
	}
	
	public static void main(String [] args) {
		System.setProperty("org.lwjgl.librarypath", new File("/lib/native/windows/").getName());
		Game game = new Game();
		game.run();
	}
}
